<template>
  <div class="public_main" >
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('newcrumbs.crumbsEle')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('newcrumbs.crumbsTwe')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('add.no100')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- ------------  今日昨日  ------------------------ -->
    <div class="tabs mb20" v-if="true">
        <el-tabs v-model="activeDay" @tab-click="dayChange">
          <el-tab-pane :label="$t('add.no29')" name="1">
          </el-tab-pane>
          <el-tab-pane :label="$t('add.no30')" name="2">
          </el-tab-pane>
        </el-tabs>
      <div class="tabs_main">
          <template>
            <el-row type="flex" class="row-bg" justify="space-between" :gutter="40" >
              <el-col :md="8" :lg="8" :xl="8">
                <div class="line">
                  <div id="myChart1" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.machineApproveList[0].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.machineApproveList[1]"><span class="box1 color2"></span><span class="mr10">{{echartData.machineApproveList[1].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.machineApproveList[2]"><span class="box1 color3"></span><span class="mr10">{{echartData.machineApproveList[2].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.machineApproveList[3]"><span class="box1 color4"></span><span class="mr10">{{echartData.machineApproveList[3].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.machineApproveList[4]"><span class="box1 color5"></span><span class="mr10">{{echartData.machineApproveList[4].remark}}</span></p>
                </div> -->
              </el-col>
              <el-col :md="8" :lg="8" :xl="8">
                <div class="line">
                  <div id="myChart2" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.firstApproveList[0].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.firstApproveList[1]"><span class="box1 color2"></span><span class="mr10">{{echartData.firstApproveList[1].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.firstApproveList[2]"><span class="box1 color3"></span><span class="mr10">{{echartData.firstApproveList[2].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.firstApproveList[3]"><span class="box1 color4"></span><span class="mr10">{{echartData.firstApproveList[3].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.firstApproveList[4]"><span class="box1 color5"></span><span class="mr10">{{echartData.firstApproveList[4].remark}}</span></p>
                </div> -->
              </el-col>
              <el-col :md="8" :lg="8" :xl="8" v-if="echartData.secondApproveList.length">
                <div class="line">
                  <div id="myChart3" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.secondApproveList[0].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.secondApproveList[1]"><span class="box1 color2"></span><span class="mr10">{{echartData.secondApproveList[1].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.secondApproveList[2]"><span class="box1 color3"></span><span class="mr10">{{echartData.secondApproveList[2].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.secondApproveList[3]"><span class="box1 color4"></span><span class="mr10">{{echartData.secondApproveList[3].remark}}</span></p>
                  <p class="flex mb10" v-if="echartData.secondApproveList[4]"><span class="box1 color5"></span><span class="mr10">{{echartData.secondApproveList[4].remark}}</span></p>
                </div> -->
              </el-col>
            </el-row>
          </template>
      </div>
    </div>
    <!-- ------------  本周上周  ------------------------ -->
    <div class="tabs mb20" v-if="true">
      <el-tabs v-model="activeWeek" @tab-click="weekChange">
          <el-tab-pane :label="$t('add.no31')" name="3">
          </el-tab-pane>
          <el-tab-pane :label="$t('add.no32')" name="4">
          </el-tab-pane>
        </el-tabs>
        <div class="tabs_main">
            <el-row type="flex" class="row-bg" justify="space-between" :gutter="40" >
              <el-col :md="8" :lg="8" :xl="8">
                <div class="line">
                  <div id="myChart4" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.machineApproveList[0]}}</span></p>
                  <p class="flex mb10"><span class="box1 color2"></span><span class="mr10">{{echartData.machineApproveList[1]}}</span></p>
                  <p class="flex mb10"><span class="box1 color3"></span><span class="mr10">{{echartData.machineApproveList[2]}}</span></p>
                  <p class="flex mb10"><span class="box1 color4"></span><span class="mr10">{{echartData.machineApproveList[3]}}</span></p>
                  <p class="flex mb10"><span class="box1 color5"></span><span class="mr10">{{echartData.machineApproveList[4]}}</span></p>
                </div> -->
              </el-col>
              <el-col :md="8" :lg="8" :xl="8">
                <div class="line">
                  <div id="myChart5" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.firstApproveList[0]}}</span></p>
                  <p class="flex mb10"><span class="box1 color2"></span><span class="mr10">{{echartData.firstApproveList[1]}}</span></p>
                  <p class="flex mb10"><span class="box1 color3"></span><span class="mr10">{{echartData.firstApproveList[2]}}</span></p>
                  <p class="flex mb10"><span class="box1 color4"></span><span class="mr10">{{echartData.firstApproveList[3]}}</span></p>
                  <p class="flex mb10"><span class="box1 color5"></span><span class="mr10">{{echartData.firstApproveList[4]}}</span></p>
                </div> -->
              </el-col>
              <el-col :md="8" :lg="8" :xl="8" v-if="echartData.secondApproveList.length">
                <div class="line">
                  <div id="myChart6" style="width: 100%;height:360px;"></div>
                </div>
                <!-- <div class="pd-lr-10 flex flex-wrap flex-align-center">
                  <p class="flex mb10"><span class="box1 color1"></span><span class="mr10">{{echartData.secondApproveList[0]}}</span></p>
                  <p class="flex mb10"><span class="box1 color2"></span><span class="mr10">{{echartData.secondApproveList[1]}}</span></p>
                  <p class="flex mb10"><span class="box1 color3"></span><span class="mr10">{{echartData.secondApproveList[2]}}</span></p>
                  <p class="flex mb10"><span class="box1 color4"></span><span class="mr10">{{echartData.secondApproveList[3]}}</span></p>
                  <p class="flex mb10"><span class="box1 color5"></span><span class="mr10">{{echartData.secondApproveList[4]}}</span></p>
                </div> -->
              </el-col>
            </el-row>
      </div>
    </div>

    <!-- ------------  列表开始  v-if="$store.state.common.permiss.includes('RIGHT_MACHINE_REJECT_EXP')"  ------------------------ --> 
    <div class="tabs" v-if="true">
        <el-tabs v-model="activeTab" @tab-click="search">
          <el-tab-pane :label="$t('channelData.day')" name="1">
          </el-tab-pane>
          <el-tab-pane :label="$t('channelData.week')" name="2">
          </el-tab-pane>
          <el-tab-pane :label="$t('channelData.mouth')" name="3">
          </el-tab-pane>
          </el-tabs>
          <div class="table-wrap">
             <el-form :inline="true" :model="formInline">
                <el-form-item :label="$t('filter.timeSelect')">
					<el-date-picker
                    v-show="activeTab == 1"
                    id="day"
                    size="small"
                    v-model="selectDay"
                    value-format="yyyy-MM-dd" 
                    type="daterange" 
                    range-separator="~" 
                    :start-placeholder="$t('public.beginTime')"
                    :end-placeholder="$t('public.endTime')">
                    </el-date-picker>
                    <el-date-picker
                    id="week"
                    v-show="activeTab == 2"    
                    v-model="weekTime"
                    type="week"
                    size="small"
                    format="yyyy 第 WW 周">
                    </el-date-picker>
                    <el-date-picker
                    id="month"
                    size="small"
                    v-show="activeTab == 3"
                    v-model="selectMonth"
                    value-format="yyyy-MM"
                    type="month">
                    </el-date-picker>
                </el-form-item>
                <el-form-item :label="$t('loanMoneyDetail.opeType2')">
					<el-select clearable size="small" v-model="formInline.approveType" :placeholder="$t('public.placeholder')">
                        <el-option v-for="item in options1" :key="item.value" :label="$t(item.label)" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('add.no94')">
                    <el-select clearable size="small" v-model="formInline.isRepeat" :placeholder="$t('public.placeholder')">
                    <el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('public.appName')">
                    <el-select clearable size="small" v-model="formInline.appName" :placeholder="$t('public.placeholder')">
                    <el-option v-for="item in appOption" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('public.appPackage')">
                    <el-select clearable size="small" v-model="formInline.appPackage" :placeholder="$t('public.placeholder')">
                    <el-option v-for="item in apkOption" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('merchantList.no1')">
                    <el-select clearable size="small" v-model="formInline.appName" :placeholder="$t('public.placeholder')">
                    <el-option v-for="item in options3" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button  v-if="true" type="primary" size="small" @click="search">{{$t('public.select')}}</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button v-if="true" type="primary" size="small" @click="putExcel"><span>{{$t('public.excel')}}</span></el-button>
                </el-form-item>
             </el-form>
            <div class="table">
              <template>
                <el-table :data="list" size="small" >
                  <el-table-column align="center" :label="$t('channelData.no1')" width="200px">
                    <template slot-scope="scope">
                      <span v-if="parseInt(activeTab)===1">{{scope.row.approveTime}}</span>
                      <span v-if="parseInt(activeTab)===2">{{scope.row.approveTime+'~'+scope.row.approveTimeEnd}}</span>
                      <span v-if="parseInt(activeTab)===3">{{scope.row.weekTime}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column align="center" prop="approveType" :label="$t('loanMoneyDetail.opeType2')">
                    <template slot-scope="scope">
                      <span>{{$t($store.getters.auditType(scope.row.approveType))}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column align="center" prop="isRepeat" :label="$t('add.no94')">
                    <template slot-scope="scope">
                      <span>{{scope.row.isRepeat==1?$t('add.no83'):$t('add.no84')}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column align="center" prop="appName" :label="$t('public.appName')">
                  </el-table-column>
                  <el-table-column align="center" prop="appPackage" :label="$t('public.appPackage')">
                  </el-table-column>
                  <el-table-column align="center" prop="appName" :label="$t('merchantList.no1')">
                  </el-table-column>
                  <el-table-column align="center" prop="rejectReason" :label="$t('add.no35')">
                  </el-table-column>
                  <el-table-column align="center" prop="rejectPercent" :label="$t('add.no36')">
                    <template slot-scope="scope">
                      <span>{{$store.getters.twoPoint(scope.row.rejectPercent)}}</span>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column align="center" prop="registerRate" :label="$t('channelData.no10')">
                    <template slot-scope="scope">
                      <span>{{$store.getters.twoPoint(scope.row.registerRate)}}%</span>
                    </template>
                  </el-table-column> -->
                </el-table>
              </template>
            </div>

            <!-- ------------  分页显示栏  ------------------------ -->
            <el-row type="flex" justify="end">
                <div class="pages" >
                    <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="pagination.current"
                    layout="sizes, prev, pager, next, total,->"
                    :page-sizes="pagination.pageSizeOptions"
                    :page-size="pagination.pageSize"
                    @size-change="handleSizeChange"
                    :total="pagination.total">
                    </el-pagination>
                </div>
                </el-row>
          </div>
    </div>

    <!-- -------------- 底部空白------------------------ -->
    <div class="foot"></div>
  </div>
</template>
<script>
  // 引入基本模板
let echarts = require('echarts/lib/echarts')
// 引入折线图组件 bar柱状图
require('echarts/lib/chart/bar')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/grid')
import putExcel from 'src/mixins/putExcel.js';//导出excel
import getApp from 'src/mixins/getApp.js';//获取app和aok
export default {
  name: 'rejectSelect',
  mixins:[getApp,putExcel],
  data () {
    return {
      flag: true,
      activeDay: '1',
      activeWeek: '3',
      activeTab:'1',
      list: [],
      formInline:{},
      selectDay: [],
      weekTime: '',
      selectMonth: '',
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      echartData:{
        firstApproveList:[],
        secondApproveList:[],
        machineApproveList:[]
      },
      formInline: {
        approveType: '',
        isRepeat:'',
        timeType:'1',
        approveTimeBegin:'',
        approveTimeEnd:'',
        appName:'',
        appPackage:''
      },
      isRepeat: -1,
      appOption:[],
      apkOption:[],
      options1: this.$store.state.options.auditType_option,
      options2: [
        { value: -1, label :this.$t('add.no83')},
        { value: 1, label :this.$t('add.no84')}
      ],
      options3:[],
      putExcelUrl:this.$action.risk_approveRejectExp
    }
  },
  methods: {
    dataListChart (val) { // 获取页面数据
      let active=val
      let option = {
        param:{
            timeType:active
        } 
      }
      this.$axios.post(this.$action.risk_approveRejectTop, option).then(res => {
        if (res.code == 200) {
          this.echartData.firstApproveList = res.data.firstApproveList;
          this.echartData.secondApproveList = res.data.secondApproveList;
          this.echartData.machineApproveList = res.data.machineApproveList;
          if(active==1||active==2){
              this.drawLine('myChart1',this.$t('add.no33'), this.echartData.machineApproveList);
              this.drawLine('myChart2',this.$t('add.no40'), this.echartData.firstApproveList);
              this.drawLine('myChart3',this.$t('add.no41'), this.echartData.secondApproveList);
          }
          if(active==3||active==4){
              this.drawLine('myChart4',this.$t('add.no33'), this.echartData.machineApproveList);
              this.drawLine('myChart5',this.$t('add.no40'), this.echartData.firstApproveList);
              this.drawLine('myChart6',this.$t('add.no41'), this.echartData.secondApproveList);
          }
        }
      })
    },
    drawLine (domId, title, data) {    // 今日数据
      myChart = echarts.init(document.getElementById(domId));
      this.getEchart(myChart, title, data);
    },
    getEchart(dom,title,data){
      dom.setOption({
        legend: {
            type: 'scroll',
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            data: data.remark,
            selected: data.selected
        },
        title: {
          text: title,
          left: 'center',
          top: 10,
          textStyle: {
            color: '#333'
          }
        },
        xAxis: {
            type : 'category',
        },
        yAxis: {
            type : 'value'
        },
        series: [
            {
                type: 'bar',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        formatter: '{c}%'
                    }
                },
                data: data,
                itemStyle: {
                    normal: {
                        // 随机显示
                        //color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                        // 定制显示（按顺序）
                        color: function(params) { 
                            var colorList = ['#C33531','#EFE42A','#64BD3D','#EE9201','#29AAE3']; 
                            return colorList[params.dataIndex] 
                        }
                    },
                },
            },
        ]
      })
    },
    fetchData () {
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.risk_approveRejectList, option).then(res => {
        this.loadFlag = false;
        if (res.code == 200) {
          this.list = res.data.list;
          this.pagination.total = res.data.total;
        } else {
          this.$message.error(res.message);
        }
      })
    },
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.fetchData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.fetchData();
    },
    getDaysInMonth(year,month){
      month = parseInt(month,10);
      var temp = new Date(year,month,0);
      return temp.getDate();
    },
    search () {
      if(this.activeTab==1){
        this.formInline.approveTimeBegin = this.selectDay[0];
        this.formInline.approveTimeEnd = this.selectDay[1];
      }else if(this.activeTab==2){
        if(this.weekTime){
          let beginTime = new Date(this.weekTime).getTime();
          let endTime=beginTime+(6*24*60*60*1000);
          this.formInline.approveTimeBegin = this.$store.getters.getYMD(beginTime);
          this.formInline.approveTimeEnd = this.$store.getters.getYMD(endTime);
        }        
      }else{
        if(this.selectMonth){
          let date=new Date(this.selectMonth);
          let year=date.getFullYear();
          let month=date.getMonth()+1;
          this.formInline.approveTimeBegin =this.selectMonth +'-01';
          this.formInline.approveTimeEnd = this.selectMonth+'-'+this.getDaysInMonth(year,month);
        }
      }
      this.pagination.current = 1;
      this.fetchData();
    },
    dayChange(){
      this.dataListChart(this.activeDay);
    },
    weekChange(){
      this.dataListChart(this.activeWeek);
    }
  },
  mounted () {
    this.getApp().then(app=>{
      this.appOption=app.appName;
      this.apkOPtion=app.appPackage;
    })
    this.dataListChart(1);
    this.dataListChart(3);
    this.fetchData();
  }
}
</script>
<style scoped lang="scss">

.line{
  width: 100%;
  height: auto;
}
.color1{
  background-color: #C33531;
}
.color2{
  background-color: #EFE42A;
}
.color3{
  background-color: #64BD3D;
}
.color4{
  background-color: #EE9201;
}
.color5{
  background-color: #29AAE3;
}
.box1{
  display: block;
  width: 2px;
  height: 20px;
  margin-right: 5px;
}
.mr10{
  margin-right: 10px;
}
.mb10{
  margin-bottom: 10px;
}
.pd-lr-10{
  padding: 0 10px;
  margin-top: -26px;
  p{
    width: 50%;
    font-size: 12px;
  }
}
.tabs {
  background: #fff;
  padding: 20px;
}
.top-wrap {
  height: 80px;
  .checkbox-wrap  {
    padding:10px;
  }
}

</style>
